package h0827;

import java.util.Arrays;

/**
 * @author 不知名帅哥
 * @version 1.0
 * @description 最长连续序列
 * @date 2024/8/27 22:54
 */
public class LongestContinuousSequence {
    public static void main(String[] args) {
        int[] nums = {100,4,200,1,3,2};
        int a = getRes(nums);
        System.out.println(a);
    }

    private static int getRes(int[] nums) {
        Arrays.sort(nums);
        int start = 0;
        int maxLen = 1;
        for (int i = 0; i < nums.length - 1; i++) {
            while (i < nums.length - 1 && nums[i] + 1 == nums[i + 1]) {
                i++;
            }
            int end = i;
            maxLen = Math.max(end - start + 1, maxLen);
            //更新start为下一个可能连续序列起始索引位置
            start=i+1;
        }
        return maxLen;
    }
}
